<?php

namespace app\admin\model\yxerp\stock;

use think\Model;

/**
 * Batch
 */
class Batch extends Model
{
    // 表名
    protected $name = 'yxerp_stock_batch';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    // 字段类型转换
    protected $type = [
        'in_time' => 'timestamp:Y-m-d H:i:s',
    ];


    public function getCostPriceAttr($value): ?float
    {
        return is_null($value) ? null : (float)$value;
    }

    public function getCostAmountAttr($value): ?float
    {
        return is_null($value) ? null : (float)$value;
    }

    public function product(): \think\model\relation\BelongsTo
    {
        return $this->belongsTo(\app\admin\model\yxerp\Product::class, 'product_id', 'id');
    }

    public function productSku(): \think\model\relation\BelongsTo
    {
        return $this->belongsTo(\app\admin\model\yxerp\product\Sku::class, 'product_sku_id', 'id');
    }

    public function warehouse(): \think\model\relation\BelongsTo
    {
        return $this->belongsTo(\app\admin\model\yxerp\Warehouse::class, 'warehouse_id', 'id');
    }
}